package com.ynny.jdbc03.dao;

import com.ynny.jdbc03.base.BaseDAO;
import com.ynny.jdbc03.entity.Student;

import java.util.List;

public class StudentDao extends BaseDAO<Student> {

    public List<Student> selectAllStudent(){

        String sql = "select * from student";
        List<Student> students = super.selectAll(sql);

        return students;

    }

    public Student selectStudentById(Integer id){
        String sql = "select * from student where id = ?";
        Student student = super.selectOne(sql, id);
        return student;
    }

    public int insertStudent(Student student){
        String sql = "insert into student(name) values(?)";
        int i = super.insert(sql, student.getName());
        return i;
    }

    public int updateStudent(Student student){

        String sql = "update student set name = ? where id = ?";

        int i = super.update(sql, student.getName(), student.getId());

        return i;
    }

    public int deleteStudent(Integer id){
        String sql = "delete from student where id = ?";
        int i = super.deleteById(sql, id);
        return i;
    }

}
